package com.ssy.lingxi.product.controller.pc.warehouse;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.product.api.model.request.warehouse.*;
import com.ssy.lingxi.product.api.model.response.warehouse.WarehouseDetailsResponse;
import com.ssy.lingxi.product.api.model.response.warehouse.WarehouseResponse;
import com.ssy.lingxi.product.service.WarehouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @menu 进销存-仓库管理
 * @author wrc
 * @date 2020/7/20
 */
@Api(tags = "仓库管理")
@RestController
@RequestMapping("/product")
public class WarehouseController extends BaseController {
    @Resource
    WarehouseService warehouseService;

    /**
     * 查询仓库列表
     * @param request
     * @return
     */
    @GetMapping("/warehouse/list")
    public Wrapper<PageData<WarehouseResponse>> warehouseList(WarehouseRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return warehouseService.warehouseList(request,sysUser);
    }

    /**
     * 查询仓库详情
     * @param id
     * @return
     */
    @GetMapping("/warehouse/details")
    public Wrapper<WarehouseResponse> warehouseDetails(Long id) {
        return warehouseService.warehouseDetails(id);
    }

    /**
     * 查询全部仓库
     * @param httpServletRequest
     * @return
     */
    @GetMapping("/warehouse/all")
    public Wrapper<List<WarehouseResponse>> warehouseAll(HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return warehouseService.warehouseAll(sysUser);
    }

    /**
     * 添加/修改仓库
     * @param request
     * @return
     */
    @PostMapping("/warehouse/addOrUpdate")
    public Wrapper<Void> warehouseAddOrUpdate(@RequestBody WarehouseAddOrUpdateRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return warehouseService.warehouseAddOrUpdate(request,sysUser);
    }

    /**
     * 删除仓库
     * @param id
     * @return
     */
    @GetMapping("/warehouse/delete")
    public Wrapper<Void> warehouseDelete(Long id) {
        return warehouseService.warehouseDelete(id);
    }

    /**
     * 启动停用仓库
     * @param request
     * @return
     */
    @PostMapping("/warehouse/startOrStop")
    public Wrapper<Void> warehouseStartOrStop(@RequestBody WarehouseStartRoStopRequest request) {
        return warehouseService.warehouseStartOrStop(request);
    }
}
